package com.zhang.servicedriveruser.service.impl;

import com.zhang.internalcommon.dto.DriverUserWorkStatus;
import com.zhang.internalcommon.dto.ResponseResult;
import com.zhang.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import com.zhang.servicedriveruser.service.IDriverUserWorkStatusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 张开琦
 * @since 2025-04-13
 */
@Service
public class DriverUserWorkStatusServiceImpl extends ServiceImpl<DriverUserWorkStatusMapper, DriverUserWorkStatus> implements IDriverUserWorkStatusService {

	@Autowired
	DriverUserWorkStatusMapper driverUserWorkStatusMapper;

	@Override
	public ResponseResult changeWorkStatus(DriverUserWorkStatus driverUserWorkStatus) {
		Long driverId = driverUserWorkStatus.getDriverId();
		Integer workStatus = driverUserWorkStatus.getWorkStatus();
		HashMap<String, Object> queryMap = new HashMap<>();
		queryMap.put("driver_id", driverId);
		List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectByMap(queryMap);
		DriverUserWorkStatus driverUserWorkStatus1 = driverUserWorkStatuses.get(0);
		driverUserWorkStatus1.setWorkStatus(workStatus);
		LocalDateTime now = LocalDateTime.now();
		driverUserWorkStatus1.setGmtModified(now);
		driverUserWorkStatusMapper.updateById(driverUserWorkStatus1);
		return ResponseResult.success("");
	}
}
